import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { fileURLToPath } from 'url'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  
  resolve: {
    alias: {
      '@': resolve(fileURLToPath(new URL('.', import.meta.url)), 'src')
    }
  },
  
  css: {
    preprocessorOptions: {
      scss: {
        api: 'modern-compiler', // 使用现代 Sass API
        silenceDeprecations: ['legacy-js-api'], // 静默旧版 API 警告
        additionalData: (content, filename) => {
          // 自动导入 variables.scss 和 global.scss，提供 Sass 变量和全局样式
          if (filename.includes("variables.scss") || filename.includes("global.scss")) {
            return content
          }
          return `@use "@/styles/variables.scss" as *;\n@use "@/styles/global.scss" as *;\n${content}`
        },
        includePaths: [resolve(fileURLToPath(new URL(".", import.meta.url)), "src")]
      }
    }
  },

  server: {
      port: 5167,
      host: true,
      proxy: {
        '/prod-api': {
          target: 'https://cms-test.cedim.cn', // 测试
          // target: 'http://192.168.100.132:8080', // 线上
          // target: 'http://172.28.10.171:8080', // 腾飞本地
          // target: 'http://localhost:8080',
          changeOrigin: true
          // rewrite: (p) => p.replace(/^\/prod-api/, '')
        }
      }
    },
})
